package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.chronicdis.Chronicdis;

public class ChronicServlet extends BaseServlet {

	private static final long serialVersionUID = 1L;

	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
			this.doPost(req, resp);
	}
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
			String m = req.getParameter("m");
			
			if("list".equals(m)){
				process(req,resp,"/page/chronic/chronic_list.jsp");
			}else if("add".equals(m)){
				add(req,resp);
			}else if("input".equals(m)){
				process(req,resp,"/page/chronic/chronic_add.jsp");
			}else if("del".equals(m)){
				del(req,resp);
				process(req,resp,"/page/chronic/chronic_list.jsp");
			}else if("get".equals(m)){
				process(req,resp,"/page/chronic/chronic_edit.jsp");
			}else if("edit".equals(m)){
				edit(req,resp);
			}
	}
	
	protected void add(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String chroniccode = req.getParameter("chroniccode");
		String pinyincode = req.getParameter("pinyincode");
		String chronicname = req.getParameter("chronicname");
		//1:实例化User
		Chronicdis chronic =new Chronicdis();
		//2:调用方法
		try{
			chronic.addChronic(chroniccode, pinyincode, chronicname);
			process(req, resp, "/page/chronic/chronic_list.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	protected void del(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String chroniccode = req.getParameter("id");
		Chronicdis chron = new Chronicdis();
		try{
		chron.delChronic(chroniccode);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	protected void edit(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String chroniccode = req.getParameter("chroniccode");
	//	System.out.println(chroniccode);
		String pinyincode  = req.getParameter("pinyincode");
	//	System.out.println(pinyincode);
		String chronicname = req.getParameter("chronicname");
		
		Chronicdis chronic = new Chronicdis();
		try{
			chronic.editChronic(chroniccode,pinyincode,chronicname);
			process(req,resp,"/page/chronic/chronic_list.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
